using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Checkr
{
    public partial class SkinChooser : Form
    {
        private SkinManager skinMan;

        private Font tempTitleFont;
        private Color tempTitleColor;
        private Font tempContentFont;
        private Color tempContentColor;
        private Color tempHoverColor;

        private string cancelFallback;

        public SkinChooser(SkinManager skinman)
        {
            InitializeComponent();
            this.listBox1.SelectedIndexChanged += new System.EventHandler(this.selectedIndexChanged);
            skinMan = skinman;

            updateLabels();

            listSkins();
        }

        private void selectedIndexChanged(object sender, EventArgs e)
        {
            skinMan.loadSkin(Application.StartupPath + "\\skins\\" + listBox1.SelectedItem + "\\");
            updateLabels();
        }

        private void updateLabels()
        {
            label1.Font = skinMan.titleFont;
            label1.ForeColor = skinMan.titleColor;
            label2.Font = skinMan.contentFont;
            label2.ForeColor = skinMan.contentColor;
            label3.ForeColor = skinMan.hoverColor;
            tempTitleFont = skinMan.titleFont;
            tempTitleColor = skinMan.titleColor;
            tempContentFont = skinMan.contentFont;
            tempContentColor = skinMan.contentColor;
            tempHoverColor = skinMan.hoverColor;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            skinMan.loadSkin(cancelFallback);
            updateLabels();
            this.Close();
        }

        public void listSkins()
        {
            ArrayList skins = skinMan.loadSkins();
            listBox1.Items.Clear();
            foreach (String temp in skins)
            {
                string[] name = temp.Split('\\');
                if (!listBox1.Items.Contains(name[name.Length-1]))
                {
                    listBox1.Items.Add(name[name.Length - 1]);
                }
            }

            //Set selected
            string[] current = skinMan.currentSkin.Split('\\');
            listBox1.SelectedItem = current[current.Length - 2];
            cancelFallback = skinMan.currentSkin;
        }

        /*
         * Title
         */
        private void button2_Click(object sender, EventArgs e)
        {
            colorDialog1.AllowFullOpen = true;
            colorDialog1.FullOpen = true;
            colorDialog1.Color = tempTitleColor;

            if (colorDialog1.ShowDialog() != DialogResult.Cancel)
            {
                label1.ForeColor = colorDialog1.Color;
                tempTitleColor = colorDialog1.Color;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            fontDialog1.Font = tempTitleFont;
            if (fontDialog1.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
            {
                label1.Font = fontDialog1.Font;
                tempTitleFont = fontDialog1.Font;
            }
        }

        /*
         * Content
         */
        private void button4_Click(object sender, EventArgs e)
        {
            fontDialog1.Font = tempContentFont;
            if (fontDialog1.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
            {
                label2.Font = fontDialog1.Font;
                tempContentFont = fontDialog1.Font;
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            colorDialog1.AllowFullOpen = true;
            colorDialog1.FullOpen = true;
            colorDialog1.Color = tempContentColor;

            if (colorDialog1.ShowDialog() != DialogResult.Cancel)
            {
                label2.ForeColor = colorDialog1.Color;
                tempContentColor = colorDialog1.Color;
            }
        }

        /*
         * Hover
         */
        private void button6_Click(object sender, EventArgs e)
        {
            colorDialog1.AllowFullOpen = true;
            colorDialog1.FullOpen = true;
            colorDialog1.Color = tempHoverColor;

            if (colorDialog1.ShowDialog() != DialogResult.Cancel)
            {
                label3.ForeColor = colorDialog1.Color;
                tempHoverColor = colorDialog1.Color;
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                skinMan.titleFont = tempTitleFont;
                skinMan.titleColor = tempTitleColor;
                skinMan.contentFont = tempContentFont;
                skinMan.contentColor = tempContentColor;
                skinMan.hoverColor = tempHoverColor;
                skinMan.updateColoursFonts();
                skinMan.setSkin(Form1.BASE_DIR + "\\skins\\" + listBox1.SelectedItem.ToString() + "\\");
            }
            this.Close();
        }
    }
}